<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>菜单管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <jsp:include page="/css.jsp"></jsp:include>
    <style type="text/css">
        .inp1 input {
            padding-left: 3px;
            height: 30px;
        }

        .inp1 select {
            padding-left: 3px;
            height: 30px;
        }

        .inp1 button {
            width: 60px;
            height: 30px;
            background-color: #318fef;
            line-height: 30px;
            text-align: center;
            color: #fff;
            border: 0;
        }


        .inp1 div {
            margin-right: 15px;
        }
    </style>
</head>
<body style="background-color: white;">
<%--商品列表模态框--%>
<div class="modal-dialog" role="document" style="width: 80%;">
    <div class="modal-content">
        <div class="table-header action-buttons">
            <a style="color: white;" id="add">添加公益发布</a>
        </div>
        <div class="modal-body">
            <form class="form-horizontal">
                <%--发布人名称--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布人名称</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="publishName" value=""
                               placeholder="请输入发布人名称">
                    </div>
                </div>

                <%--发布人手机号--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布人手机号</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="publishPhone" value=""
                               placeholder="请输入发布人手机号">
                    </div>
                </div>

                <%--发布人所在城市--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布人所在城市</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="userscity" value=""
                               placeholder="发布人所在城市">
                    </div>
                </div>


                <%--发布人头像--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布人头像</label>
                    <div class="col-sm-10">
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="headImage" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="headImageFile"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                    </div>
                </div>


                <%--发布标题--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="publishTitle" value=""
                               placeholder="请输入发布标题">
                    </div>
                </div>


                <%--发布内容--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布内容</label>
                    <div class="col-sm-10">
                        <textarea id="content" name="content" placeholder="请输入文章内容"></textarea>
                    </div>
                </div>


                <%--发布图片--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布图片</label>
                    <div class="col-sm-10">
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image1" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile1"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image2" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile2"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image3" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile3"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image4" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile4"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image5" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile5"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image6" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile6"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image7" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile7"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image8" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile8"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                        <img src="${pageContext.servletContext.contextPath}/static/image/addimg.png"
                             style="width: 300px; height: 150px;" id="image9" value=""
                             onclick="$(this).next('input').click();"> <input
                            style="display: none;" type="file" name="file"
                            id="productimagefile9"
                            accept="image/jpg,image/jpeg,image/png,image/bmp" multiple/>
                    </div>
                </div>

                <%--发布城市--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布城市</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="city" value=""
                               placeholder="请输入发布城市">
                    </div>
                </div>

                <%--发布类型--%>
                <div class="form-group">
                    <label class="col-sm-2 control-label">发布类型</label>
                    <div class="col-sm-10">
                        <select class=" form-control " id="publishType">
                            <option selected="selected" value="生命接力">生命接力</option>
                            <option value="寻亲团圆">寻亲团圆</option>
                            <option value="爱心助学">爱心助学</option>
                        </select>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-success" onclick="save();">提交</button>
            <button type="button" class="btn btn-danger"
                    onclick="closeAble();">取消
            </button>
        </div>
    </div>
</div>

<%--商品详情模态框--%>
<div class="modal fade mymodal" id="DetailModals" tabindex="-1"
     role="dialog" aria-labelledby="myModalLabel" style="z-index:1400">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myDetailLabel">商品详情</h4>
            </div>
            <div class="modal-body">
                <div id="contentfont"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">取消
                </button>
            </div>
        </div>
    </div>
</div>

<jsp:include page="/js.jsp"></jsp:include>

<script type="text/javascript">

    $("#headImageFile").change(function () {
        UploadImg('headImageFile', '#headImage');
    });

    $("#productimagefile1").change(function () {
        UploadImg('productimagefile1', '#image1');
    });
    $("#productimagefile2").change(function () {
        UploadImg('productimagefile2', '#image2');
    });
    $("#productimagefile3").change(function () {
        UploadImg('productimagefile3', '#image3');
    });
    $("#productimagefile4").change(function () {
        UploadImg('productimagefile4', '#image4');
    });
    $("#productimagefile5").change(function () {
        UploadImg('productimagefile5', '#image5');
    });
    $("#productimagefile6").change(function () {
        UploadImg('productimagefile6', '#image6');
    });
    $("#productimagefile7").change(function () {
        UploadImg('productimagefile7', '#image7');
    });
    $("#productimagefile8").change(function () {
        UploadImg('productimagefile8', '#image8');
    });
    $("#productimagefile9").change(function () {
        UploadImg('productimagefile9', '#image9');
    });

    function save() {
        /*发布人名称*/
        var publishName = $("#publishName").val();
        if (!isNotNull(publishName)) {
            layer.msg("请输入发布人名称", {icon: 0});
            return;
        }

        /*发布人手机号*/
        var publishPhone = $("#publishPhone").val();
        if (!IsPhone(publishPhone)) {
            layer.msg("请输入正确得手机号", {icon: 0});
            return;
        }

        /*发布人所在城市*/
        var userscity = $("#userscity").val();
        if (!isNotNull(userscity)) {
            layer.msg("请输入发布人所在城市", {icon: 0});
            return;
        }

        /*发布人头像*/
        var headImage = $("#headImage").attr("src");
        if (!isNotNull(headImage)) {
            layer.msg("请上传发布人头像", {icon: 0});
            return;
        }

        /*发布标题*/
        var publishTitle = $("#publishTitle").val();
        if (!isNotNull(publishTitle)) {
            layer.msg("请输入发布标题", {icon: 0});
            return;
        }

        /*发布内容*/
        var detail = $("#content").val();
        if (!isNotNull(detail)) {
            layer.msg("请填写发布内容", {icon: 0});
            return;
        }


        /*发布图片*/
        var image1 = $("#image1").attr("src");
        var image2 = $("#image2").attr("src");
        var image3 = $("#image3").attr("src");
        var image4 = $("#image4").attr("src");
        var image5 = $("#image5").attr("src");
        var image6 = $("#image6").attr("src");
        var image7 = $("#image7").attr("src");
        var image8 = $("#image8").attr("src");
        var image9 = $("#image9").attr("src");
        var images;
        if (isNotNullimage(image1)) {
            images = image1
        }
        if (isNotNullimage(image2)) {
            images = image1 + "," + image2
        }
        if (isNotNullimage(image3)) {
            images = image1 + "," + image2 + "," + image3
        }
        if (isNotNullimage(image4)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4
        }
        if (isNotNullimage(image5)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4 + "," + image5
        }
        if (isNotNullimage(image6)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4 + "," + image5 + "," + image6
        }
        if (isNotNullimage(image7)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4 + "," + image5 + "," + image6 + "," + image7
        }
        if (isNotNullimage(image8)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4 + "," + image5 + "," + image6 + "," + image7 + "," + image8
        }
        if (isNotNullimage(image9)) {
            images = image1 + "," + image2 + "," + image3 + "," + image4 + "," + image5 + "," + image6 + "," + image7 + "," + image8 + "," + image9
        }
        /*发布城市*/
        var city = $("#city").val();
        if (!isNotNull(city)) {
            layer.msg("请输入发布城市", {icon: 0});
            return;
        }

        /*请选择发布类型*/
        var publishType = $("#publishType").val();
        if (!isNotNull(publishType) || publishType == "0") {
            layer.msg("请选择发布类型", {icon: 0});
            return;
        }
        var jsonObj = new Object();
        jsonObj.publishName = publishName;
        jsonObj.publishPhone = publishPhone;
        jsonObj.headImage = headImage;
        jsonObj.publishTitle = publishTitle;
        jsonObj.detail = detail;
        jsonObj.images = images;
        jsonObj.city = city;
        jsonObj.publishType = publishType;
        jsonObj.userscity = userscity;
        $.ajax({
            url: "${pageContext.servletContext.contextPath}/publish/addPublishWelfare",
            type: "post",
            data: {"strJson": JSON.stringify(jsonObj)},
            success: function (data) {
                if (data.code == 200) {
                    layer.msg("发布成功", {"icon": 1});
                } else {
                    layer.msg(data.desc, {"icon": 0})
                }
            }
        })
    }


</script>
</body>

</html>
